package com.xsoft.web.util.excel;



import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class ExcelWorkBook {
	 public HSSFWorkbook workbook = null;   
	    //设置当前workbookName   
	    private String workbookName = null;   
	    private HSSFSheet sheet = null;   
	    private FileOutputStream fileOut;   
	       
	    public ExcelWorkBook() {   
	    }   
	       
	    public ExcelWorkBook(String workbookName) {   
	        setWorkbookName(workbookName);   
	    }   
	    public String getWorkbookName() {   
	        return workbookName;   
	    }   
	  
	  
	    public void setWorkbookName(String workbookName) {
			this.workbookName = workbookName;
		}

		public HSSFSheet getSheet() {   
	        sheet = workbook.createSheet(this.getWorkbookName());
	        return sheet;   
	    }   
	       
	    /**  
	     * 用于stylUtils的所需要的workbook必须项所做的处理  
	     * @return  
	     */  
	       
	    /**  
	     * 输入当前WorkBook为下载临时文件记录  
	     * @param excelName  
	     */  
	    public void writerFileStream(String excelName) {   
	        try {   
	            fileOut = new FileOutputStream(excelName);   
	            workbook.write(fileOut);   
	        } catch (FileNotFoundException e) {   
	            e.printStackTrace();   
	        } catch (IOException e) {   
	            e.printStackTrace();   
	        } finally {   
	            try {   
	                fileOut.flush();   
	                fileOut.close();   
	                if(workbook != null) {   
	                    workbook = null;   
	                }   
	            } catch (IOException e) {   
	                e.printStackTrace();   
	            }   
	        }   
	    }

		public HSSFWorkbook getWorkbook() {
			return workbook;
		}

		public void setWorkbook(HSSFWorkbook workbook) {
			this.workbook = workbook;
		}

		public FileOutputStream getFileOut() {
			return fileOut;
		}

		public void setFileOut(FileOutputStream fileOut) {
			this.fileOut = fileOut;
		}

		public void setSheet(HSSFSheet sheet) {
			this.sheet = sheet;
		}   

}
